package math.base;

/**
 * @author Saga
 *
 */
public class Quaternion {
    public Quaternion(final double _w, final double _x, final double _y, final double _z) {
        this.w = _w;
        this.x = _x;
        this.y = _y;
        this.z = _z;
    }

    public final Matrix3d toMatrix() {
        final double xx = x * x * 2.0;
        final double yy = y * y * 2.0;
        final double zz = z * z * 2.0;
        final double xy = x * y * 2.0;
        final double xz = x * z * 2.0;
        final double xw = x * w * 2.0;
        final double yz = y * z * 2.0;
        final double yw = y * w * 2.0;
        final double zw = z * w * 2.0;

        return new Matrix3d(1.0 - yy - zz, xy + zw, xz - yw,
                xy - zw, 1.0 - xx - yy, yz + xw,
                xz + yw, yz - xw, 1.0 - xx - yy);
    }

    private final double w;
    private final double x;
    private final double y;
    private final double z;
}
